/**
 * 查看图片广告
 */
function viewAd(){
	var adId = getQueryString("adId");
	var adCode = getQueryString("adCode");
	if(adId != null){//根据广告id查询
		$.ajax({
			url : '/web-adv/viewAd',
	        data:{adId:adId},
			type : 'post',
			success : function(data) {
				var resultVo = data.resultVo;
				var picServerPrex = resultVo.picServerPrex;//图片服务器路径
				var ads = data.bean;
				$("#adName").html(ads.adName);	//广告名
				$("#advUrl").html(ads.advUrl); //广告链接
				$(".adCoverImg").attr("src",picServerPrex+ads.adHomepage);//广告封面
				$(".adKeyword").html(ads.adKey);//关键字
				$(".adDescribe").html(ads.description);//描述
				var terminalType = ads.terminalType; //终端
				
				//图片
				var pictureUrl;
				switch(terminalType){
					case "tv":
						pictureUrl = ads.tvVUrl;
						break;
					case "mobile":
						pictureUrl = ads.mobileVUrl;
						break;
					case "pad":
						pictureUrl = ads.padVUrl;
						break;
					case "pc":
						pictureUrl = ads.pcVUrl;
						break;
						default:
							pictureUrl = "";
				}
				
				//广告属性标签
				var classfyIds = ads.adClassify.split("|");
				for(var i =0;i<classfyIds.length;i++){
					if(classfyIds[i].length != 0){
					//	console.log(classfyIds[i]);
						var li = "<li><img src=\"/web-adv/advWeb/static/images/genres_pic"+classfyIds[i]+".png\" alt=\"\" /></li>";
						$("#adClassify").append(li);
					}
				}
				//终端  （mobile，pc，pad，tv）手机、PC、PAD、互联网电视
				switch(terminalType){
					case 'mobile':
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/mobileIcon.png");
						$("#terminal :nth-child(2)").html("手机");
						$("#size").html(ads.mobileSize);
						break
					case 'pc':
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/pcIcon.png");
						$("#terminal :nth-child(2)").html("PC");
						$("#size").html(ads.pcSize);
						break
					case 'pad':
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/padIcon.png");
						$("#terminal :nth-child(2)").html("PAD");
						$("#size").html(ads.padSize);
						break
					case 'tv':
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/tvIcon.png");
						$("#terminal :nth-child(2)").html("互联网电视");
						$("#size").html(ads.tvSize);
						break
					default:
				}
				if(pictureUrl.length != 0){
					var imgUrls = pictureUrl.split("|");
					var li="";
					var imgNum=3-(imgUrls.length-1)%3;
					if(imgNum==3){
						imgNum=0;
					}
					for(var i=0;i<imgUrls.length;i++){
						if(imgUrls[i].length !=0){
							li+="<li class='left'>"+
							         "<img src='"+picServerPrex+imgUrls[i]+"' alt='' />"+
									 "<div class='adCoverFilmsBtnGroup'>"+
									 	"<div class='clear'></div>"+
									 "</div>"+
							    "</li>";
						}
					}
					for(var j=0;j<imgNum;j++){
						li+="<li class='left'>"+
						         "<img src='' alt='' index='"+j+"'/>"+
								 "<div class='adCoverFilmsBtnGroup'>"+
								 	"<div class='clear'></div>"+
								 "</div>"+
						    "</li>";
					}
					$(".adCoverFilmsWrap").append(li);	
					var ulInitLeft=$(".adCoverFilmsWrap li").length/3*1035;  //初始向左便宜一套ul的长度
					$(".adCoverFilmsWrap").css("left",-ulInitLeft+"px");
					$(".adCoverFilmsWrap").append(li);
					$(".adCoverFilmsWrap").append(li);
				}
			},
	        error: function(){}        
		});
	}else{//根据广告编号 查询
		$.ajax({
			url : '/web-adv/viewAdByAdCode',
	        data:{adCode:adCode},
			type : 'post',
			success : function(data) {
				var resultVo = data.resultVo;
				var picServerPrex = resultVo.picServerPrex;//图片服务器路径
				var ads = data.bean;
				$("#adName").html(ads.adName);	//广告名
				$("#advUrl").html(ads.advUrl); //广告链接
				$(".adCoverImg").attr("src",picServerPrex+ads.adHomepage);//广告封面
				$(".adKeyword").html(ads.adKey);//关键字
				$(".adDescribe").html(ads.description);//描述
				var terminalType = ads.terminalType; //终端
				//图片
				var pictureUrl;
				switch(terminalType){
					case "tv":
						pictureUrl = ads.tvVUrl;
						break;
					case "mobile":
						pictureUrl = ads.mobileVUrl;
						break;
					case "pad":
						pictureUrl = ads.padVUrl;
						break;
					case "pc":
						pictureUrl = ads.pcVUrl;
						break;
						default:
							pictureUrl = "";
				}
				//广告属性标签
				var classfyIds = ads.adClassify.split("|");
				for(var i =0;i<classfyIds.length;i++){
					if(classfyIds[i].length != 0){
						console.log(classfyIds[i]);
						var li = "<li><img src=\"/web-adv/advWeb/static/images/genres_pic"+classfyIds[i]+".png\" alt=\"\" /></li>";
						$("#adClassify").append(li);
					}
				}
				//终端  （mobile，pc，pad，tv）手机、PC、PAD、互联网电视
				switch(terminalType){
					case 'mobile':
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/mobileIcon.png");
						$("#terminal :nth-child(2)").html("手机");
						$("#size").html(ads.mobileSize);
						break
					case 'pc':
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/pcIcon.png");
						$("#terminal :nth-child(2)").html("PC");
						$("#size").html(ads.pcSize);
						break
					case 'pad':
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/padIcon.png");
						$("#terminal :nth-child(2)").html("PAD");
						$("#size").html(ads.padSize);
						break
					case 'tv':
						$("#terminal :nth-child(1)").attr("src","/web-adv/advWeb/static/images/tvIcon.png");
						$("#terminal :nth-child(2)").html("互联网电视");
						$("#size").html(ads.tvSize);
						break
					default:
				}
				
				if(pictureUrl.length != 0){
					var imgUrls = pictureUrl.split("|");
					var li="";
					var imgNum=3-(imgUrls.length-1)%3;
					for(var i=0;i<imgUrls.length;i++){
						if(imgUrls[i].length !=0){
							li+="<li class='left'>"+
						         "<img src='"+picServerPrex+imgUrls[i]+"' alt='' />"+
								 "<div class='adCoverFilmsBtnGroup'>"+
								 	"<div class='clear'></div>"+
								 "</div>"+
						    "</li>";
						}
						//$(".adCoverFilmsWrap").append(li);
					}
					for(var j=0;j<imgNum;j++){
						li+="<li class='left'>"+
						         "<img src='' alt='' index='"+j+"'/>"+
								 "<div class='adCoverFilmsBtnGroup'>"+
								 	"<div class='clear'></div>"+
								 "</div>"+
						    "</li>";
					}
					
					$(".adCoverFilmsWrap").append(li);	
					var ulInitLeft=$(".adCoverFilmsWrap li").length/3*1035;
					$(".adCoverFilmsWrap").css("left",-ulInitLeft+"px");
					$(".adCoverFilmsWrap").append(li);
					$(".adCoverFilmsWrap").append(li);
				}
			},
	        error: function(){}        
		});
	}
}
